package com.situ.day1;

import org.junit.Test;

import java.util.Random;
import java.util.Scanner;

public class WhileForSwitchDemo {

   /* 1.循环条件的初始化
    2.循环条件的控制
    3.循环条件的改变*/
    @Test
    public void test1() {
        int i = 1;
        while (i <= 5) {
            System.out.println("HelloWorld");
            i++;
        }
    }

    @Test
    public void test2() {
        for (int i = 1; i <= 5; i++) {
            System.out.println("HelloWorld");
        }
    }

    //1、累加思想（1+2+3+... + 100）
    @Test
    public void test12() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            System.out.println(i);
            //sum = sum + i;
            sum += i;
            System.out.println("sum: " + sum);
        }
        System.out.println("sum: " + sum);
    }

    //2、统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test23() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 ==  0) {
                System.out.println(i);
                count++;
            }
        }
        System.out.println("count: " + count);
    }

    @Test
    public void test44() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                continue;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test45() {
        for (int i = 1; i <= 5; i++) {
            if (i == 3) {
                break;
            }
            System.out.println(i);
        }
    }

    @Test
    public void test46() {
        //i,j,k
        for (int i = 1; i <= 5; i++) {
            System.out.println("i: " + i);
            for (int j = 1; j <= 5; j++) {
                if (j == 3) {
                    break;
                }
                System.out.println("j: " + j);
            }
        }
    }

    @Test
    public void test333() {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        //include exclude
        //int value between zero (inclusive) and bound (exclusive)
        // [0,100) + 1
        // [1,100) + 1
        int num = random.nextInt(100) + 1;
        System.out.println("num: " + num);
        while (true) {
            System.out.println("猜吧");
            int guess = scanner.nextInt();
            if (guess > num) {
                System.out.println("太大了");
            } else if (guess < num) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜你，猜对了");
                break;
            }
        }

        // ...

    }

    @Test
    public void test3331() {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        //include exclude
        //int value between zero (inclusive) and bound (exclusive)
        // [0,100) + 1
        // [1,100) + 1
        int num = random.nextInt(100) + 1;
        System.out.println("num: " + num);
        for (;;) {
            System.out.println("猜吧");
            int guess = scanner.nextInt();
            if (guess == num) {
                System.out.println("恭喜你，猜对了");
                break;
            }

            if (guess > num) {
                System.out.println("太大了");
            } else if (guess < num) {
                System.out.println("太小了");
            }
        }

        // ...

    }


//        ****
//        ****
//        ****
    @Test
    public void test77() {
        //****
        for (int i = 1; i <= 4; i++) {
            System.out.print("*");
        }
        System.out.println();//换行
        //*
        //*
        //*
        for (int i = 1; i <= 3; i++) {
            System.out.println("*");
        }
    }

    @Test
    public void test334() {
        //i,j,k
        for (int i = 1; i <= 3; i++) {
            //i=1 打印第一行
            for(int j = 1; j <= 4; j++) {
                System.out.print("*");
            }
            //打印完一行
            System.out.println();
        }

    }

//    *
//    **
//    ***
//    ****
//    *****
    @Test
    public void test33() {
        //i=1  j=1
        //i=2  j=2
        //i=3  j=3
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void test31() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + "*" + i + "=" + (i * j) + "\t");
            }
            System.out.println();
        }
    }



}
